Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    shows: false,
    startdate: "",
    stopdate: "",
    startlabel: true,
    stoplabel: true,
    content: "",
    logo: "",
    popup: false,
    house: "",
    image: true,
    address: "",
    id: "",
    isclick: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.request({
      url: 'http://www.house.com/house',
      success: (res) => {
        let house = res.data.data;
        this.setData({
          house: house
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  calendar() {
    this.setData({
      show: true
    })
  },
  calendars() {
    this.setData({
      shows: true
    })
  },
  startdate(e) { //开始时间
    this.setData({
      startdate: e.detail
    })
    this.setData({
      startlabel: false
    })
    this.setData({
      startlabels: "开始日期:"
    })
    var startdate = this.data.startdate;
    var stopdate = this.data.stopdate;
    this.setData({
      startdate: startdate
    })
    // var start_year=new Date(startdate.replace(/-/g,'/')).getFullYear();
    // var start_month=new Date(startdate.replace(/-/g,'/')).getMonth()+1;
    // var start_date=new Date(startdate.replace(/-/g,'/')).getDate();
    // startdate=start_year+'/'+start_month+'/'+start_date;//时间转换
    if (stopdate == startdate) {
      this.showMessage({
        content: "开始日期不能等于结束日期,请重新选择",
        type: "error",
        show: true,
        duration: 4000
      })
      this.setData({
        message: true,
        startdate: "",
        startlabel: true,
      })
    }
    if (stopdate == "") {
      return true;
    } else {
      if (stopdate < startdate) {
        this.showMessage({
          content: "结束日期不能小于结束日期,请重新选择",
          type: "error",
          show: true,
          duration: 4000
        })
        this.setData({
          message: true,
          stopdate: "",
          stoplabel: true,
        })
      }
    }

  },
  stopdate(e) { //结束时间
    this.setData({
      stopdate: e.detail
    })
    this.setData({
      stoplabel: false
    })
    this.setData({
      stoplabels: "结束日期:"
    })
    var stopdate = this.data.stopdate;
    this.setData({
      stopdate: stopdate
    })
    if (this.data.startdate == stopdate) {
      this.showMessage({
        content: "结束日期不能等于开始日期,请重新选择",
        type: "error",
        show: true,
        duration: 4000
      })
      this.setData({
        message: true,
        startdate: "",
        startlabel: true,
      })
    }
    if (this.data.startdate > stopdate) {
      this.showMessage({
        content: "开始日期不能大于结束日期,请重新选择",
        type: "error",
        show: true,
        duration: 4000
      })
      this.setData({
        message: true,
        stopdate: "",
        stoplabel: true,
      })
    }

  },
  showMessage(e) {
    wx.lin.showMessage({
      content: e.content,
      type: e.type,
    })
  },
  onChangeTap(e) {
    let logo = e.detail.current[0];
    this.setData({
      logo: logo
    })
  },
  append(e) {
    let id = this.data.id;
    let logo = this.data.logo;
    let tittle = e.detail.value.tittle;
    let address = this.data.address;
    let startdate = this.data.startdate;
    let stopdate = this.data.stopdate;
    let introduce = e.detail.value.introduce;
    var time = null;
    if (logo == "") {
      wx.showModal({
        title: "提示",
        content: "房源图片不能为空",
      })
      return;
    }
    if (tittle == "") {
      wx.showModal({
        title: "提示",
        content: "团购标题不能为空",
      })
      return;
    }
    if (address == "") {
      wx.showModal({
        title: "提示",
        content: "楼盘地址不能为空",
      })
      return;
    }
    if (startdate == "") {
      wx.showModal({
        title: "提示",
        content: "开始日期不能为空",
      })
      return;
    }
    if (stopdate == "") {
      wx.showModal({
        title: "提示",
        content: "结束日期不能为空",
      })
      return;
    }
    if (introduce == "") {
      wx.showModal({
        title: "提示",
        content: "团购介绍不能为空",
      })
      return;
    }
    wx.request({
      url: 'http://www.house.com/group',
      header: {
        token: wx.getStorageSync('token')
      },
      data: {
        house_id: id,
        house_logo: logo,
        house_tittle: tittle,
        house_address: address,
        start_date: startdate,
        stop_date: stopdate,
        group_introduce: introduce
      },
      method: "POST",
      success: (ent) => {
        let code = ent.data.code;
        if (code == 2002) {
          wx.showModal({
            title: "提示",
            cancelColor: '#FF0000',
            content: "该房源团购活动已存在"
          })
        }
        if (code == 200) {
          wx.showModal({
            title: "提醒",
            content: "创建成功",
            success: (ent) => {
              if (ent.confirm) {
                wx.navigateTo({
                  url: '/pages/grouppurchase/grouppurchase',
                })
              } else if (ent.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }
        if (code == 2001) {
          wx.showModal({
            title: "提示",
            cancelColor: 'FF0000',
            content: "创建失败"
          })
        }
      }
    })
    this.setData({
      isclick: false
    });
    setTimeout(() => {
      this.setData({
        isclick: true
      }), 80000
    })
  },
  house() {
    this.setData({
      popup: true
    })
  },
  choose(e) {
    this.setData({
      popup: false
    })
    let logo = e.currentTarget.dataset.logo;
    let address = e.currentTarget.dataset.address;
    let id = e.currentTarget.dataset.id;
    this.setData({
      logo: logo
    })
    this.setData({
      address: address
    })
    this.setData({
      image: false
    })
    this.setData({
      id: id
    })
  }



















})